package com.project.service.impl;

import com.project.bean.ClassBean;
import com.project.dao.IClassDao;
import com.project.dao.IStudentDao;
import com.project.service.IClassService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ClassServiceImpl implements IClassService {
    @Autowired
    private IClassDao classDao;
    @Autowired
    private IStudentDao studentDao;

    @Override
    public List<ClassBean> findAll() {
        return classDao.findAll();
    }

    @Override
    public boolean del(int classId) {
        int num = studentDao.countByClass(classId);
        if (num == 0) {
            classDao.del(classId);
            return true;
        } else {
            return false;
        }
    }

    @Override
    public void add(ClassBean classBean) {
        classDao.add(classBean);
    }
}
